/**
 * Created by yang on 2016/3/9.
 */
angular.module('ng-safeapply', []).factory('SafeApply', function() {

    return function(scope, fn) {
        var phase = scope.$root.$$phase;
        if (phase == '$apply' || phase == '$digest') {
            if (fn) {
                scope.$eval(fn);
            }
        } else {
            if (fn) {
                scope.$apply(fn);
            } else {
                scope.$apply();
            }
        }
    };

});